package com.hlt360.util;

import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.OapiRobotSendRequest;
import com.taobao.api.ApiException;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class DingTalk {

    public static void send(String message) {
        String access_token = "0c84481ed54c758bbbdc1e3137e3ab52149dd8a5cf72970fb087168b6219c504";
        String serverUrl = "https://oapi.dingtalk.com/robot/send?access_token=" + access_token;
        DingTalkClient client = new DefaultDingTalkClient(serverUrl);
        OapiRobotSendRequest request = new OapiRobotSendRequest();
        request.setMsgtype("text");
        OapiRobotSendRequest.Text text = new OapiRobotSendRequest.Text();
        text.setContent("【油画】" + message);
        request.setText(text);
        try {
            client.execute(request);
        } catch (ApiException ex) {
            log.error("发送钉钉消息失败 - " + ex.getMessage(), ex);
        }
    }

}
